import {Component, OnInit} from '@angular/core';
import * as moment from 'moment';
import {_HttpClient} from '@delon/theme';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'school-organization',
    templateUrl: './school-organization.component.html'
})

export class SchoolOrganizationComponent implements OnInit {

    q: any = {
        ps: 8,
        province: [],
    };

    list: any[] = [];

    loading = true;

    province = [
        {id: 1, text: '不限', value: false},
        {id: 2, text: '北京', value: false},
        {id: 3, text: '天津', value: false},
        {id: 4, text: '河北', value: false},
        {id: 5, text: '山西', value: false},
        {id: 6, text: '内蒙古', value: false},
        {id: 7, text: '辽宁', value: false},
        {id: 8, text: '吉林', value: false},
        {id: 9, text: '黑龙江', value: false},
        {id: 10, text: '上海', value: false},
        {id: 11, text: '江苏', value: false},
        {id: 12, text: '浙江', value: false},
        {id: 13, text: '安徽', value: false},
        {id: 14, text: '福建', value: false},
        {id: 15, text: '江西', value: false},
        {id: 16, text: '山东', value: false},
        {id: 17, text: '河南', value: false},
        {id: 18, text: '湖北', value: false},
        {id: 19, text: '湖南', value: false},
        {id: 20, text: '广东', value: false, citys: [
                {name: '全部', value: false},
                {name: '广州', value: false},
                {name: '韶关', value: false},
                {name: '深圳', value: false},
                {name: '珠海', value: false},
                {name: '汕头', value: false},
                {name: '佛山', value: false},
                {name: '江门', value: false},
                {name: '湛江', value: false},
                {name: '茂名', value: false},
                {name: '肇庆', value: false},
                {name: '惠州', value: false},
                {name: '梅州', value: false},
                {name: '汕尾', value: false},
                {name: '河源', value: false},
                {name: '阳江', value: false},
                {name: '清远', value: false},
                {name: '东莞', value: false},
                {name: '中山', value: false},
                {name: '潮州', value: false},
                {name: '揭阳', value: false},
                {name: '云浮', value: false},
            ]},
        {id: 21, text: '广西', value: false},
        {id: 22, text: '海南', value: false},
        {id: 23, text: '重庆', value: false},
        {id: 24, text: '四川', value: false},
        {id: 25, text: '贵州', value: false},
        {id: 26, text: '云南', value: false},
        {id: 27, text: '西藏', value: false},
        {id: 28, text: '陕西', value: false},
        {id: 29, text: '甘肃', value: false},
        {id: 30, text: '青海', value: false},
        {id: 31, text: '宁夏', value: false},
        {id: 32, text: '新疆', value: false},
    ];

    cityLists = [
        {
            province: '广东',
            citys: [
                {name: '全部', value: false},
                {name: '广州', value: false},
                {name: '韶关', value: false},
                {name: '深圳', value: false},
                {name: '珠海', value: false},
                {name: '汕头', value: false},
                {name: '佛山', value: false},
                {name: '江门', value: false},
                {name: '湛江', value: false},
                {name: '茂名', value: false},
                {name: '肇庆', value: false},
                {name: '惠州', value: false},
                {name: '梅州', value: false},
                {name: '汕尾', value: false},
                {name: '河源', value: false},
                {name: '阳江', value: false},
                {name: '清远', value: false},
                {name: '东莞', value: false},
                {name: '中山', value: false},
                {name: '潮州', value: false},
                {name: '揭阳', value: false},
                {name: '云浮', value: false},
            ],
        },
    ];

    batch = [
        {id: 1, name: '不限', value: false},
        {id: 2, name: '一本', value: false},
        {id: 3, name: '二本', value: false},
        {id: 4, name: '专科', value: false},
    ];

    changeCategory(status: boolean, idx: number) {
        if (idx === 0) {
            this.province.map(i => i.value = status);
        } else {
            this.province[idx].value = status;
        }
        this.getData();
    }

    constructor(private http: _HttpClient, public msg: NzMessageService) {
    }

    ngOnInit() {
        this.getData();
    }

    getData() {
        this.loading = true;
        this.http.get('', {count: this.q.ps}).subscribe((res: any) => {
            this.list = res.map(item => {
                if (item.updatedAt) item.updatedAt = moment(item.updatedAt).fromNow();
                // item.activeUser = this.formatWan(item.activeUser);
                return item;
            });
            this.loading = false;
        });
    }


}
